<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /**
     * @var Zend_Log
     */
    protected $_logger;

    /**
     * @var Zend_Application_Module_Autoloader
     */
    protected $_resourceLoader;

    /**
     * @var Zend_Controller_Front
     */
    public $frontController;

    /**
     * Setup the logging
     */
    protected function _initLogging()
    {
         $this->bootstrap('frontController');
//       $this->frontController = $this->getResource('frontController');
        $logger = new Zend_Log();

        $writer = 'production' == $this->getEnvironment() ?
			new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/logs/app.log') :
			new Zend_Log_Writer_Firebug();
        $logger->addWriter($writer);
        
        $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
        $logger->addFilter($filter);

        $this->_logger = $logger;
        //$logger->log($message, $priority);
        Zend_Registry::set('log', $logger);
    }

     /**
     * Setup the view
     */
    protected function _initViewSettings()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $this->bootstrap('view');

        $this->_view = $this->getResource('view');

        // add global helpers
        $this->_view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'Zend_View_Helper');

        // set encoding and doctype
        $this->_view->setEncoding('UTF-8');
        $this->_view->doctype('XHTML1_STRICT');

        // set the content type and language
        $this->_view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
        $this->_view->headMeta()->appendHttpEquiv('Content-Language', 'en-US');

        // set css links and a special import for the accessibility styles
        // $this->_view->headStyle()->setStyle('@import "/css/style_all.css";');
        $this->_view->headLink()->appendStylesheet('/css/style.css');

        //$this->_view->headLink()->appendStylesheet('../../css/style.css');
        
        $this->_view->headScript()->appendFile($this->_view->baseUrl() . 'js/jquery.js', 'text/javascript' );
        //$this->_view->headScript()->appendFile($this->_view->baseUrl() . 'js/jcycle.js', 'text/javascript' );
        
        // setting the site in the title
        $this->_view->headTitle('Online Will');

        // setting a separator string for segments:
        $this->_view->headTitle()->setSeparator(' - ');
    }

    /**
     * Setup locale
     */
    protected function _initLocale()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $locale = new Zend_Locale('en_US');
        Zend_Registry::set('Zend_Locale', $locale);
    }

    /**
     * Setup the database profiling
     */
    protected function _initDbProfiler()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        if ('production' !== $this->getEnvironment()) {
            $this->bootstrap('db');
            $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
            $profiler->setEnabled(true);
            $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler);
        }
    }

    /**
     * Add the config to the registry
     */
    protected function _initConfig()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);
        Zend_Registry::set('config', $this->getOptions());
    }

     /**
     * Add required routes to the router
     */
    
    protected function _initRoutes()
    {
        
        $this->_logger->info('Bootstrap ' . __METHOD__);
        $this->bootstrap('frontController');

        $router = $this->frontController->getRouter();

        // dashboard url router
        $route = new Zend_Controller_Router_Route_Static(
            '/home',
            array(
                'action'     => 'index',
                'controller' => 'index',
                'module'     => 'static',
            )
        );
        $router->addRoute('home', $route);

        // login url router
        $route = new Zend_Controller_Router_Route_Static(
            '/login',
            array(
                'action'     => 'index',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('login', $route);

        // logout url router
        $route = new Zend_Controller_Router_Route_Static(
            '/logout',
            array(
                'action'     => 'logout',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('logout', $route);

        // dashboard url router
        $route = new Zend_Controller_Router_Route_Static(
            '/dashboard',
            array(
                'action'     => 'index',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('dashboard', $route);
        
        $route = new Zend_Controller_Router_Route_Static(
            '/profile',
            array(
                'action'     => 'profile',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('profile', $route);


        $route = new Zend_Controller_Router_Route_Static(
            '/edit-profile',
            array(
                'action'     => 'edit',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('edit-profile', $route);


        //  loginpost url router
        $route = new Zend_Controller_Router_Route_Static(
            '/loginpost',
            array(
                'action'     => 'loginpost',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('loginpost', $route);

        //  register url router
        $route = new Zend_Controller_Router_Route_Static(
            '/register',
            array(
                'action'     => 'register',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('register', $route);

        //  verify url router
        $route = new Zend_Controller_Router_Route(
            '/verify/:VerificationCode',
            array(
                'action'     => 'verify',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('verify', $route);
        
        //  forgot url router
        $route = new Zend_Controller_Router_Route_Static(
            '/forgot',
            array(
                'action'     => 'forgot',
                'controller' => 'account',
                'module'     => 'main',
            )
        );
        $router->addRoute('forgot', $route);
        
        //  my-assets url router
        $route = new Zend_Controller_Router_Route_Static(
            '/my-assets',
            array(
                'action'     => 'index',
                'controller' => 'index',
                'module'     => 'asset',
            )
        );
        $router->addRoute('my-assets', $route);

        //  add-asset url router
        $route = new Zend_Controller_Router_Route_Static(
            '/add-asset',
            array(
                'action'     => 'addasset',
                'controller' => 'index',
                'module'     => 'asset',
            )
        );
        $router->addRoute('add-asset', $route);
        
        $route = new Zend_Controller_Router_Route_Static(
            '/save-asset',
            array(
               'action'      => 'save',
                'controller' => 'index',
                'module'     => 'asset',
            )
        );
        $router->addRoute('save-asset', $route);
        
        // edit asset
        $route = new Zend_Controller_Router_Route(
            '/edit-asset/:assetid',
            array(
                'action'     => 'editasset',
                'controller' => 'index',
                'module'     => 'asset',
                'assetid'    => '',
            )
                ,array('assetid' => '[0-9]+')
        );
        $router->addRoute('edit-asset', $route);
        
        // update asset
        $route = new Zend_Controller_Router_Route_Static(
            '/update-asset',
            array(
                'action'     => 'updateasset',
                'controller' => 'index',
                'module'     => 'asset',
                
            )
        );
        $router->addRoute('update-asset', $route);
        
        // delete asset
        $route = new Zend_Controller_Router_Route(
            '/delete-asset/:assetid',
            array(
                'action'     => 'deleteasset',
                'controller' => 'index',
                'module'     => 'asset',
                
            )
        );
        $router->addRoute('delete-asset', $route);
        
        //  add-liability url router
        $route = new Zend_Controller_Router_Route_Static(
            '/add-liability',
            array(
                'action'     => 'addLiability',
                'controller' => 'index',
                'module'     => 'asset',
            )
        );
        $router->addRoute('add-liability', $route);

        //  my-family url router
        $route = new Zend_Controller_Router_Route_Static(
            '/my-family',
            array(
                'action'     => 'index',
                'controller' => 'index',
                'module'     => 'family',
            )
        );
        $router->addRoute('my-family', $route);

        //  add-address url router
        $route = new Zend_Controller_Router_Route_Static(
            '/add-address',
            array(
                'action'     => 'newaddress',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('add-address', $route);
        
        //  add-address url router
        $route = new Zend_Controller_Router_Route_Static(
            '/address-post',
            array(
                'action'     => 'addresspost',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('address-post', $route);
        
        //  edit-address url router
        $route = new Zend_Controller_Router_Route_Static(
            '/edit-address',
            array(
                'action'     => 'editaddress',
                'controller' => 'profile',
                'module'     => 'main',
            )
        );
        $router->addRoute('edit-address', $route);
        
    }

    /**
     * Configure the default modules autoloading, here we first create
     * a new module autoloader specifiying the base path and namespace
     * for our default module. This will automatically add the default
     * resource types for us. We also add two custom resources for Services
     * and Model Resources.
     */
    protected function _initDefaultModuleAutoloader()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Static',
            'basePath'  => APPLICATION_PATH . '/modules/static',
        ));
        $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Asset',
            'basePath'  => APPLICATION_PATH . '/modules/asset',
        ));
        $this->_resourceLoader->addResourceTypes(array(
            'modelResource' => array(
              'path'      => 'models/resources',
              'namespace' => 'Resource',
            ),

            'form' => array(
                    'path' => 'forms',
                    'namespace' => 'Form',
               ),

        ));
        
    }
    /**
     * fucntion autoloads the different modules 
     */
    
    protected function _initAllModuleAutoloader()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);
      
        $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Main',
            'basePath'  => APPLICATION_PATH . '/modules/main',
        ));
        $this->_resourceLoader->addResourceTypes(array(
            'modelResource' => array(
              'path'      => 'models/resources',
              'namespace' => 'Resource',
            ),

            'form' => array(
                    'path' => 'forms',
                    'namespace' => 'Form',
               ),
            'service' => array(
                    'path' => 'services',
                    'namespace' => 'Service',
                    ),

        ));

        $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Family',
            'basePath'  => APPLICATION_PATH . '/modules/family',
        ));
        $this->_resourceLoader->addResourceTypes(array(
            'modelResource' => array(
              'path'      => 'models/resources',
              'namespace' => 'Resource',
            ),

            'form' => array(
                    'path' => 'forms',
                    'namespace' => 'Form',
               ),
            
        ));

  /*
        $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Dataform',
            'basePath'  => APPLICATION_PATH . '/modules/dataform',
        ));
        $this->_resourceLoader->addResourceTypes(array(
            'modelResource' => array(
              'path'      => 'models/resources',
              'namespace' => 'Resource',
            ),

            'form' => array(
                    'path' => 'forms',
                    'namespace' => 'Form',
               ),

        ));
       */
    }

 
     /**
     * Add Controller Action Helpers
     */
    protected function _initActionHelpers()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);
       // Zend_Controller_Action_HelperBroker::addHelper(new WOW_Controller_Helper_Acl());
       // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_RedirectCommon());
        // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_Service());
    }

}